ifndef CROSS_COMPILE
CROSS_COMPILE=
endif

#define these for disconnecting between main directory and subdirectory.
ifndef top_srcdir
top_srcdir= ..
endif

ifndef EXECUTE_FILE
EXECUTE_FILE= host_demo_exe
endif


CC	= $(CROSS_COMPILE)gcc
#CC = $(CROSS_COMPILE)mips-linux-uclibc-gcc

STRIP	= $(CROSS_COMPILE)strip
#STRIP = $(CROSS_COMPILE)mips-linux-uclibc-strip

HOST_DEMO_OBJDIR:=Objects
HOST_DEMO_DEPDIR:=Objects

TOPDIR := $(shell pwd)/../

DYM_ZLOG_PATH= ../Lib/
DYM_ZLOG= -lzlog

LDFLAGS =  -lm -lpthread
LDFLAGS += $(DYM_ZLOG)


WARNING = 

INCLUDEFLAGS=-I$(TOPDIR)Include/

OSFLAG = -DCTC_STACK -DLINUX -D_GNU_SOURCE -D_REENTRANT -DETHERNET_HOST -DSYS_DUMP -DREMOTE_MANAGEMENT -DERROR_DEBUG -DCRITICAL_ERROR_DEBUG -DMAX_OLT_ID_15
CFLAGS = $(OSFLAG) $(WARNING) $(INCLUDEFLAGS)
#CFLAGS_REL = -Os
CFLAGS_REL = -I ../../HOST_REMOTE_MANAGEMENT/SNMP/SNMP_AGENT

PLATFORM_DIR= $(top_srcdir)/Platform
CLI_DIR= $(top_srcdir)/CLI
MAIN_DIR= $(top_srcdir)/Host
APP_DIR= $(top_srcdir)/App
LOG_DIR= $(top_srcdir)/Log
SNMP_DIR= $(top_srcdir)/SNMP
LIB_DIR= $(top_srcdir)/Lib

HOST_DEMO_DIRS := \
	$(top_srcdir)/\
	$(MAIN_DIR)/\
	$(PLATFORM_DIR)/ETHERNET/ \
	$(PLATFORM_DIR)/OSSRV/ \
	$(PLATFORM_DIR)/OSSRV_SOCKETS/ \
	$(PLATFORM_DIR)/TIMER/ \
	$(PLATFORM_DIR)/DEBUG/\
	$(PLATFORM_DIR)/MSGQUEN\
	$(PLATFORM_DIR)/THREAD\
	$(SNMP_DIR)/\
	$(CLI_DIR)/ \
	$(CLI_DIR)/CLI_COMMANDS/GENERAL_COMMAND/ \
	$(CLI_DIR)/CLI_ENGINE/
	

# Source files
MAIN_SRCS := \
	Main 

PLATFORM_SRCS := \
	ETHERNET_Linux \
	OSSRV_Linux \
	OSSRV_SOCKETS_Linux \
	sys_timer\
	sys_debug\
	sys_debug_cmd\
	sys_debug_process\
	sys_debug_server\
	sys_msgque\
	sys_threadmgr

APP_SRCS := 


SNMP_SRCS := \
	snmp


CLI_SRCS := \
	cli_start \
	general_commands \
	buffer \
	cli_vector \
	command \
	filter \
	hash \
	log \
	memory \
	prefix \
	sockunion \
	thread \
	vty

HOST_DEMO_SRCS := \
	$(MAIN_SRCS) \
	$(PLATFORM_SRCS) \
	$(CLI_SRCS)\
	$(SNMP_SRCS)\
	$(APP_SRCS)


vpath %.c $(HOST_DEMO_DIRS)

APP_NAME := $(EXECUTE_FILE)

HOST_DEMO_OBJS:= $(HOST_DEMO_SRCS:%=$(HOST_DEMO_OBJDIR)/%.o)
HOST_DEMO_DEPS:= $(HOST_DEMO_SRCS:%=$(HOST_DEMO_DEPDIR)/%.d)
HOST_DEMO_TARGETDIR = Bin


.PHONY: all clean release debug

all: $(HOST_DEMO_TARGETDIR)/$(APP_NAME)


$(HOST_DEMO_TARGETDIR)/$(APP_NAME): $(HOST_DEMO_OBJS) Makefile
	@echo linking  $@
	@[ -d $(HOST_DEMO_TARGETDIR) ] || mkdir $(HOST_DEMO_TARGETDIR)
	#@$(CC) $(HOST_DEMO_OBJS) $(LDFLAGS) -o $@
	@$(CC) $(HOST_DEMO_OBJS) -L$(DYM_ZLOG_PATH)  $(LDFLAGS) -o $@
	@$(STRIP) --strip-unneeded  -R=.comment -R=.note $@


clean:
	@echo clean
	@rm -rf Objects $(HOST_DEMO_TARGETDIR)

$(HOST_DEMO_OBJDIR)/%.o: %.c Makefile
	@[ -d $(HOST_DEMO_DEPDIR) ] || mkdir -p $(HOST_DEMO_DEPDIR)
	@[ -d $(HOST_DEMO_OBJDIR) ] || mkdir -p $(HOST_DEMO_OBJDIR)
	@echo compiling $<
	@$(CC) -MMD -MF $(HOST_DEMO_DEPDIR)/$(*F).d -MT $@ $(CFLAGS) $(CFLAGS_REL) -c $< -o $@
	@[ -s $(HOST_DEMO_DEPDIR)/$(*F).d ] || rm -f $(HOST_DEMO_DEPDIR)/$(*F).d


-include $(HOST_DEMO_DEPS)


